﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class DelMaterialmanagementCommandHanders : IRequestHandler<DelMaterialmanagementCommands, APIResult<Materialmanagement>>
    {
        private readonly IBaseRepository<Materialmanagement> MaterialmanagementRepository;
        private readonly IMapper mapper;

        public DelMaterialmanagementCommandHanders(IBaseRepository<Materialmanagement> materialmanagementRepository, IMapper mapper)
        {
            MaterialmanagementRepository = materialmanagementRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 删除物料产品信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Materialmanagement>> Handle(DelMaterialmanagementCommands request, CancellationToken cancellationToken)
        {
            APIResult<Materialmanagement> result = new APIResult<Materialmanagement>();
            result.Code= APIEnum.删除成功;
            result.Msg = "删除成功";
            var map = mapper.Map<Materialmanagement>(request);
            var list = $"Update Materialmanagement set IsDelete=true where MId='{request.MId}'";
            await MaterialmanagementRepository.Update(map, list);
            return result;
        }
    }
}
